<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <title>ShellCheck: SC2018 – Use `[:lower:]` to support accents and foreign alphabets.</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>
  <body style="margin-left: auto; margin-right: auto; max-width: 800px">
    <h1>SC2018 – ShellCheck Wiki</h1>
    <a href="https://github.com/koalaman/shellcheck/wiki/SC2018">See this page on GitHub</a>
    <p style="display: none"><a href="index.html">Sitemap</a></p>
    <hr />
    <h2 id="use-lower-to-support-accents-and-foreign-alphabets">Use
<code>[:lower:]</code> to support accents and foreign alphabets.</h2>
<h3 id="problematic-code">Problematic code:</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="SC2018.html#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="va">PLATFORM</span><span class="op">=</span><span class="st">&quot;</span><span class="va">$(</span><span class="fu">uname</span> <span class="at">-s</span> <span class="kw">|</span> <span class="fu">tr</span> <span class="st">&#39;A-Z&#39;</span> <span class="st">&#39;a-z&#39;</span><span class="va">)</span><span class="st">&quot;</span></span></code></pre></div>
<h3 id="correct-code">Correct code:</h3>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="SC2018.html#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="va">PLATFORM</span><span class="op">=</span><span class="st">&quot;</span><span class="va">$(</span><span class="fu">uname</span> <span class="at">-s</span> <span class="kw">|</span> <span class="fu">tr</span> <span class="st">&#39;[:upper:]&#39;</span> <span class="st">&#39;[:lower:]&#39;</span><span class="va">)</span><span class="st">&quot;</span></span></code></pre></div>
<h3 id="rationale">Rationale:</h3>
<p><code>A-Z</code> and <code>a-z</code> are commonly intended to mean
"all uppercase" and "all lowercase letters" respectively. This ignores
accented characters in English, and foreign characters in other
languages:</p>
<pre><code>$ tr &#39;a-z&#39; &#39;A-Z&#39; &lt;&lt;&lt; &quot;My fiancée ordered a piña colada.&quot;
MY FIANCéE ORDERED A PIñA COLADA.</code></pre>
<p>Instead, you can use <code>[:lower:]</code> and
<code>[:upper:]</code> to explicitly specify case:</p>
<pre><code>$ tr &#39;[:lower:]&#39; &#39;[:upper:]&#39; &lt;&lt;&lt; &quot;My fiancée ordered a piña colada.&quot;
MY FIANCÉE ORDERED A PIÑA COLADA.</code></pre>
<h3 id="exceptions">Exceptions:</h3>
<p>If you don't want <code>a-z</code> to match <code>é</code> or
<code>A-Z</code> to match <code>Ñ</code>, you can ignore this
message.</p>
<p>As of 2019-09-08, BusyBox <code>tr</code> does not support character
classes, so you would have to ignore this message.</p>
<p>Note that the examples used here are multibyte characters in UTF-8.
Many implementations (including GNU) fails to deal with them.</p>
    <hr />
    <p style='font-size: 80%'><a href="../index.html">ShellCheck</a> is a static analysis tool for shell scripts. This page is part of its documentation.</p>
  </body>
</html>


